package cn.sdormitory.canteen.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.sdormitory.canteen.dao.CanteenBuyDao;
import cn.sdormitory.canteen.dao.CanteenStockDetailDao;
import cn.sdormitory.canteen.service.CanteenStockDetailService;
import cn.sdormitory.canteen.vo.CanteenBuyVO;
import cn.sdormitory.canteen.vo.CanteenStockDetailVO;
import cn.sdormitory.common.api.CommonPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("canteenStockDetailService")
public class CanteenStockDetailServiceImpl extends ServiceImpl<CanteenStockDetailDao, CanteenStockDetailVO> implements CanteenStockDetailService {

    @Autowired
    private  CanteenStockDetailDao canteenStockDetailDao;

    @Override
    public CommonPage<CanteenStockDetailVO> getPage(Map<String, Object> params) {
        int pageSize = Integer.parseInt(String.valueOf(params.get("pageSize")));
        int pageNum = Integer.parseInt(String.valueOf(params.get("pageNum")));

        List<CanteenStockDetailVO> list = this.canteenStockDetailDao.getCanteenStockList(params, (pageNum - 1) * pageSize, pageSize);
        CommonPage commonPage = CommonPage.getCommonPage(pageNum, pageSize, this.canteenStockDetailDao.getCanteenStockListCount(params), list);

        return commonPage;
    }

    @Override
    public int stockUpdate(CanteenStockDetailVO vo) {
        return 0;
    }

    @Override
    public int stockAdd(CanteenStockDetailVO vo) {
        return canteenStockDetailDao.insert(vo);
    }

    @Override
    public int outStock(CanteenStockDetailVO vo) {
        Map<String,Object> params = new HashMap<>();
        params.put("supplier",vo.getSupplier());
        params.put("goodsName",vo.getGoodsName());
        //根据名称和供应商查询采购商品的数量
        List<CanteenStockDetailVO> list = this.canteenStockDetailDao.getCanteenStockList(params, 1, 10);
        if(list!=null){
            CanteenStockDetailVO detailVO = list.get(0);
            detailVO.getSurplusNum();
        }
        //商品数量不够给出提示
        return 0;
    }
}
